﻿Imports ADOConnection
Imports System.IO
Imports System

Public Class MainForm
    Private user_kho As Boolean = False
    Private enumNX As enumDOITUONG
    'Kiem tra xem 1 instance form da mo roi chua?
    ' The String WndCls is the windows full path. Namespace.Classname 
    'Public Function CheckMdiClientDuplicates(ByVal WndCls As String) As Boolean
    '    Dim mdichld As Form() = Me.MdiChildren
    '    If Me.MdiChildren.Length = 0 Then
    '        Return True
    '    End If
    '    For Each selfm As Form In mdichld
    '        Dim str As String = selfm.Name
    '        str = str.IndexOf(WndCls).ToString()
    '        If str <> "-1" Then
    '            Return True
    '        End If
    '    Next
    '    Return False
    'End Function

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetEnableSomeMenus(False)
        Dim frm As New frmLogin
        frm.ShowDialog()
        If LoginOK Then
            If CUsers.isAdmin(g_UserName) Then
                SetEnableSomeMenus(True)
            Else
                HienThiMenuTheoQuyen()
            End If
        End If
    End Sub


#Region "ToolStripMenu"

#Region "He Thong"
    Private Sub DangNhapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DangNhapToolStripMenuItem.Click
        MainForm_Load(Nothing, Nothing)
    End Sub

    Private Sub DangXuatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DangXuatToolStripMenuItem.Click
        For Each frm As Form In Me.MdiChildren
            frm.Close()
        Next
        'dang xuat
        SetEnableSomeMenus(False)
        DangNhapToolStripMenuItem.Enabled = True
        'Reset connectString
        connectString = ""
        LoginOK = False
    End Sub

    Private Sub DoiMatKhauToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoiMatKhauToolStripMenuItem.Click
        'cho phep doi mat khau nguoi dung
        Dim frm As New frmDoiPassword()
        frm.ShowDialog()
    End Sub

    Private Sub BackupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupToolStripMenuItem.Click
        Dim frm As New frmBackup(True)
        frm.ShowDialog()
    End Sub

    Private Sub PhânQuyềnToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhânQuyềnToolStripMenuItem.Click
        Dim startInfo As System.Diagnostics.ProcessStartInfo
        Dim pStart As New System.Diagnostics.Process

        startInfo = New System.Diagnostics.ProcessStartInfo(Application.StartupPath & "\Chuong trinh Quan ly Nguoi dung.exe")
        pStart.StartInfo = startInfo
        pStart.Start()
        'pStart.WaitForExit() 'Your code will halt until the exe file has executed.
    End Sub

    Private Sub TrichLuuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrichLuuToolStripMenuItem.Click
        Dim frm As New frmTrichLuuDuLieu()
        frm.ShowDialog()
    End Sub

    Private Sub ThoatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoatToolStripMenuItem.Click
        Me.Close()
    End Sub

    ''Chuc nang nay dung de cap nhat lai danh muc menu cho tblMenu trong CSDL
    'Private Sub ThoatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoatToolStripMenuItem.Click
    '    Dim frm As New frmChonMenu(Me)
    '    frm.Show()
    'End Sub
#End Region

#Region "DU LIEU"
    Private Sub DMPhieuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMPhieuToolStripMenuItem.Click
        Dim frmLP As New frmLocPhieu
        frmLP.Init()
        frmLP.PopulateDK()
        frmLP.Close()
        Dim frm As New frmViewPhieuNX
        frm.MdiParent = Me
        frm.Show()
        If frm.WindowState = FormWindowState.Maximized Then
            frm.WindowState = FormWindowState.Normal
            'frm.Size = frm.MdiParent.ClientSize
            'frm.Location = New Point(0, 0)
            frm.WindowState = FormWindowState.Maximized
        End If
    End Sub

    Private Sub DMLoHangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMLoHangToolStripMenuItem.Click
        Dim frm As New frmQuanLyLoHang()
        frm.ShowDialog()
    End Sub

    Private Sub ThemPhieuNhapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemPhieuNhapToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            enumNX = enumDOITUONG.TINHCHATNHAP
            ThemPhieuMoi()
        End If
    End Sub

    Private Sub ThemPhieuXuatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemPhieuXuatToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            enumNX = enumDOITUONG.TINHCHATXUAT
            ThemPhieuMoi()
        End If
    End Sub

    Private Sub ChuyenNoiBoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChuyenNoiBoToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            Dim frm As New frmPhieuNXNoiBo
            frm.MdiParent = Me
            frm.Show()
        End If
    End Sub

    Private Sub DCSLSSThuaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DCSLSSThuaToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            enumNX = enumDOITUONG.TINHCHATNHAP
            Dim frmPhieu As New frmPhieuNXDCSS
            frmPhieu.enumNX = enumDOITUONG.TINHCHATNHAP
            frmPhieu.MdiParent = Me
            frmPhieu.Show()
        End If
    End Sub

    Private Sub DCSLSSThieuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DCSLSSThieuToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            enumNX = enumDOITUONG.TINHCHATXUAT
            Dim frmPhieu As New frmPhieuNXDCSS
            frmPhieu.enumNX = enumDOITUONG.TINHCHATXUAT
            frmPhieu.MdiParent = Me
            frmPhieu.Show()
        End If
    End Sub

    Private Sub DMHopDongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMHopDongToolStripMenuItem.Click
        Dim frm As New frmHopDong
        frm.ShowDialog()
    End Sub

    Private Sub DMThuocToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMThuocToolStripMenuItem.Click
        Dim frm As New frmVatTu
        frm.ShowDialog()
    End Sub

    Private Sub DMKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMKhoToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Kho"
        frm.eDoiTuong = enumDOITUONG.KHO
        frm.ShowDialog()
    End Sub

    Private Sub DMLoaiKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMLoaiKhoToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Loại kho"
        frm.eDoiTuong = enumDOITUONG.LOAIKHO
        frm.ShowDialog()
    End Sub

    Private Sub DMDonViToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMDonViToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Đơn vị"
        frm.eDoiTuong = enumDOITUONG.DONVI
        frm.ShowDialog()
    End Sub

    Private Sub DanhMucTinhChatNhapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DanhMucTinhChatNhapToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Tính chất nhập"
        frm.eDoiTuong = enumDOITUONG.TINHCHATNHAP
        frm.ShowDialog()
    End Sub

    Private Sub DMTinhChatXuatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMTinhChatXuatToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Tính chất xuất"
        frm.eDoiTuong = enumDOITUONG.TINHCHATXUAT
        frm.ShowDialog()
    End Sub

    Private Sub DanhMucDonViTinhToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMDonViTinhToolStripMenuItem.Click
        Dim frm As New frmDMDoiTuong
        frm.Text = "Danh mục Đơn vị tính"
        frm.eDoiTuong = enumDOITUONG.DVT
        frm.ShowDialog()
    End Sub
#End Region

#Region "KIEM KE"
    Private Sub mnuKiemKe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KiemKeVatTuToolStripMenuItem.Click
        If KiemTraChuyenDuLieu() Then
            Dim frm As New frmChonKyKiemKe
            frm.ShowDialog()
        End If
    End Sub

    Private Sub KiemTraChenhLechToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KiemTraMatHangKhongKhopSoLieuToolStripMenuItem.Click
        Dim frm As New frmKiemTraMatHangChenhLech()
        frm.ShowDialog()
    End Sub

    Private Sub ChuyenDuLieuKyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChuyenDuLieuDauNamToolStripMenuItem.Click
        Dim frm As New frmChuyenDuLieuKy
        frm.Show()
    End Sub

    Private Sub BáoCáoKiểmKêTheoNhómHàngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoKiểmKêTheoNhómHàngToolStripMenuItem.Click
        Dim frm As New frmBaoCaoKiemKeTheoNhomHang
        frm.ShowDialog()
    End Sub

    Private Sub ĐiềuChỉnhSốLượngSổSáchTháng7ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐiềuChỉnhSốLượngSổSáchTháng7ToolStripMenuItem1.Click
        If (MsgBox("Bạn muốn thay đổi Số Lượng Sổ Sách Tháng 7", MsgBoxStyle.YesNo, "Chú ý") = MsgBoxResult.Yes) Then
            Try
                BaseDB.ExecSqlProcedure_Command("sp_UpdateSoLieuSoSachThang7")
                MsgBox("Điều chỉnh xong")
            Catch ex As Exception
            End Try
        End If
    End Sub

    Private Sub BáoCáoKiểmKêTháng7BằngLờiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoKiểmKêTháng7BằngLờiToolStripMenuItem.Click
        Dim frm As New frmBaoCaoKiemKeBangLoi
        frm.ShowDialog()
    End Sub
#End Region

#Region "BAO CAO KE HOACH"

    Private Sub BáoCáoChiTiếtHàngNhậpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoChiTiếtHàngNhậpToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongHopNhapXuatTheoDonVi("BaoCaoChiTietHangNhap")
        frm.ShowDialog()
    End Sub

    Private Sub BáoCáoTổngHợpHàngNhậpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoTổngHợpHàngNhậpToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongHopNhapXuatTheoDonVi("BaoCaoTongHopHangNhap")
        frm.ShowDialog()
    End Sub

    Private Sub TổngHợpKếHoạchNhậpXuấtTheoĐơnVịToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TổngHợpKếHoạchNhậpXuấtTheoĐơnVịToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongHopNhapXuatTheoDonVi("BaoCaoTongHopNhapXuat")
        frm.ShowDialog()
    End Sub

    Private Sub TổngGiáTrịLệnhNhậpXuấtTheoĐơnVịToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TổngGiáTrịLệnhNhậpXuấtTheoĐơnVịToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongGiaTriNhapXuatTheoDonVi
        frm.ShowDialog()
    End Sub

    Private Sub TổngHợpKếHoạchNhậpXuấtTheoCácĐơnVịToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TổngHợpKếHoạchNhậpXuấtTheoCácĐơnVịToolStripMenuItem.Click
        Dim frm As New frmTongHopNhapXuatCacDonVi
        frm.ShowDialog()
    End Sub

    Private Sub BáoCáoTổngGiáTrịThuốcHóaChấtBôngBăngĐãCấpCácĐơnVịToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoTổngGiáTrịĐãCấpCácĐơnVịToolStripMenuItem.Click
        Dim frm As New frmTongHopTHCBBDaCapChoCacDonVi("BaoCaoTongGiaTriDaCapChoCacDonVi")
        frm.ShowDialog()
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        'Tong gia tri nhap theo tung loai kho
        'tuog tu nhu form BaoCaoTongGiaTriDaCapChoCacDonVi
        Dim frm As New frmTongHopTHCBBDaCapChoCacDonVi("BaoCaoTongGiaTriDaNhapChoCacDonVi")
        frm.ShowDialog()
    End Sub

    Private Sub BáoCáoHàngTồnKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoHàngTồnKhoToolStripMenuItem.Click
        Dim frm As New frmBaoCaoHangTonKho("taichinh")
        frm.ShowDialog()
    End Sub

    Private Sub BáoCáoHàngTồnKhoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoHàngTồnKhoToolStripMenuItem1.Click
        Dim frm As New frmBaoCaoHangTonKho("kehoach")
        frm.ShowDialog()
    End Sub

    Private Sub TổngGiáTrịNhậpXuấtTheoCácĐơnVịToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TổngGiáTrịNhậpXuấtTheoCácĐơnVịToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongGiaTriNhapTheoCacDonVi
        frm.ShowDialog()
    End Sub
#End Region

#Region "BAO CAO TAI CHINH"

    Private Sub TongHopHangMuaNhapKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TongHopHangMuaNhapKhoToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTaiChinhTheoKyQT("TongHopHangMuaNhapKho")
        frm.ShowDialog()
    End Sub

    Private Sub TổngHợpHàngXuấtChoLLTTToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TổngHợpHàngXuấtChoLLTTToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTaiChinhTheoKyQT("TongHopHangXuatChoLL-TT")
        frm.ShowDialog()
    End Sub

    Private Sub TổngHợpHàngTăngGiảmPhẩmChấtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TổngHợpHàngTăngGiảmPhẩmChấtToolStripMenuItem.Click
        Dim frm As New frmBaoCaoTongHopHangTangGiamPhamChat
        frm.ShowDialog()
    End Sub

    Private Sub mnuitemBaoCaoKetQuaNhapHangTuXN150_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuitemBaoCaoKetQuaNhapHangTuXN150.Click
        Dim frm As New frmBaoCaoNhapXuatTheoDonVi
        frm.ShowDialog()
    End Sub

    Private Sub BáoCáoHàngNhậpXuấtTheoTínhChấtNhậpXuấtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BáoCáoHàngNhậpXuấtTheoTínhChấtNhậpXuấtToolStripMenuItem.Click
        'Dim frm As New frmBaoCaoHangNhapXuatTheoTCNX
        Dim frm As New frmBaoCaoTaiChinhTheoKyQT("BaoCaoNhapXuatTheoTCNX")
        frm.ShowDialog()
    End Sub

    Private Sub mnuitemBangKeChungTu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuitemBangKeChungTu.Click
        Dim frm As New frmBangKeChungTu
        frm.ShowDialog()
    End Sub
    
#End Region

#Region "CAC TIEN ICH"
    Private Sub ChọnKếtNốiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChọnKếtNốiToolStripMenuItem.Click
        Dim startInfo As System.Diagnostics.ProcessStartInfo
        Dim pStart As New System.Diagnostics.Process

        startInfo = New System.Diagnostics.ProcessStartInfo(Application.StartupPath & "\DBConnect.udl")
        pStart.StartInfo = startInfo
        pStart.Start()

        DangXuatToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub QuảnLýMenuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuảnLýMenuToolStripMenuItem.Click
        If Not g_User.IsAdmin() Then
            ShowMessages("Bạn không có quyền thực hiện chức năng này.")
            Exit Sub
        End If
        Dim frm As New frmChonMenu(Me)
        frm.Show()
    End Sub
#End Region
    
#Region "Cac Cua So Dang Mo"
    Private Sub CascadeWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CascadeWindowToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub ArrangeWindowsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArrangeWindowsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub TitleVerticalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TitleVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TitleHorizonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TitleHorizonToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub
#End Region

#End Region

#Region "ToolStripButton"
    Private Sub ThoatToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoatToolStripButton.Click
        ThoatToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DangNhapToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DangNhapToolStripButton.Click
        DangNhapToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DangXuatToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DangXuatToolStripButton.Click
        DangXuatToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DMPhieuToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMPhieuToolStripButton.Click
        DMPhieuToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DMLoHangToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DMLoHangToolStripButton.Click
        DMLoHangToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub ThemPhieuNhapToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemPhieuNhapToolStripButton.Click
        ThemPhieuNhapToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub ThemPhieuXuatToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemPhieuXuatToolStripButton.Click
        ThemPhieuXuatToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub ChuyenNoiBoToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChuyenNoiBoToolStripButton.Click
        ChuyenNoiBoToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DCSLSSThuaToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DCSLSSThuaToolStripButton.Click
        DCSLSSThuaToolStripMenuItem_Click(Nothing, Nothing)
    End Sub

    Private Sub DCSLSSThieuToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DCSLSSThieuToolStripButton.Click
        DCSLSSThieuToolStripMenuItem_Click(Nothing, Nothing)
    End Sub
#End Region

#Region "FUNCTIONS"
    Private Sub GetstrWhereDMKhoByUser()
        Dim strSql As String = "select KHO from tblUSER where user_id = '" + g_User.User_ID.ToString() + "'"
        Dim value, strDK As String
        strDK = ""
        value = BaseDB.ExecSql_DataValue(strSql)
        If value <> "" Then 'and (Not value Is DBNull.Value) Then
            'user nay co quyen vao kho minh quan ly
            user_kho = True
            Dim data() As String = value.Split(";")
            For Each item As String In data
                If Len(strDK) > 0 Then
                    strDK &= " OR (KH = '" & item & "')"
                Else
                    strDK = " where (KH = '" & item & "')"
                End If
            Next
        End If

        'Code Bo sung de loc dung Danh muc kho
        If strDK <> "" Then
            strDK &= " and L = 'K'"
        Else
            strDK &= " where L = 'K'"
        End If
        strWhereDMKhoByUser = strDK
    End Sub

    Private Sub SetEnableSomeMenus(ByVal val As Boolean)
        For i As Integer = 0 To MenuStrip1.Items.Count - 2
            Dim menu As ToolStripMenuItem = MenuStrip1.Items(i)
            For j As Integer = 0 To menu.DropDownItems.Count - 1
                Try
                    Dim m As ToolStripMenuItem = menu.DropDownItems(j)
                    m.Enabled = val
                Catch ex As Exception
                End Try
            Next
        Next

        For k As Integer = 0 To ToolStrip1.Items.Count - 1
            Try
                Dim toolStrip As ToolStripButton = ToolStrip1.Items(k)
                toolStrip.Enabled = val
            Catch ex As Exception
            End Try
        Next

        DangNhapToolStripMenuItem.Enabled = Not val
        DangNhapToolStripButton.Enabled = DangNhapToolStripMenuItem.Enabled
        ThoatToolStripMenuItem.Enabled = True
        ThoatToolStripButton.Enabled = ThoatToolStripMenuItem.Enabled
        ChọnKếtNốiToolStripMenuItem.Enabled = True
    End Sub


    Private Sub HienThiMenuTheoQuyen()
        'disable menu dang nhap
        DangNhapToolStripMenuItem.Enabled = False
        DangNhapToolStripButton.Enabled = DangNhapToolStripMenuItem.Enabled
        DangXuatToolStripMenuItem.Enabled = True
        DangXuatToolStripButton.Enabled = DangXuatToolStripMenuItem.Enabled
        DoiMatKhauToolStripMenuItem.Enabled = True
        ThoatToolStripMenuItem.Enabled = True
        ThoatToolStripButton.Enabled = ThoatToolStripMenuItem.Enabled
        Try
            'thuc hien hien thi cac menu tren form

            For Each Menu As String In dsQuyenTrenForm
                For Each ctrl As Control In Me.Controls
                    If ctrl.Name Is "MenuStrip1" Then
                        Dim tool() As ToolStripItem = MenuStrip1.Items.Find(Trim(Menu), True)
                        If tool.Length > 0 Then
                            tool(0).Enabled = True
                        End If
                    End If
                    If ctrl.Name = "ToolStrip1" Then
                        Dim strToolStripButtonName As String = Menu.Substring(0, Menu.Length - CStr("ToolStripMenuItem").Length) + "ToolStripButton"
                        Dim tool2() As ToolStripItem = ToolStrip1.Items.Find(strToolStripButtonName, True)
                        If tool2.Length > 0 Then
                            tool2(0).Enabled = True
                        End If
                    End If
                Next
            Next
        Catch ex As Exception
        End Try
    End Sub

    Public Sub ThemPhieuMoi()
        Dim frmPhieu As New frmPhieuNX
        If enumNX = enumDOITUONG.TINHCHATNHAP Then
            frmPhieu.enumNX = enumDOITUONG.TINHCHATNHAP
        ElseIf enumNX = enumDOITUONG.TINHCHATXUAT Then
            frmPhieu.enumNX = enumDOITUONG.TINHCHATXUAT
        End If
        frmPhieu.MdiParent = Me
        frmPhieu.Show()
    End Sub
#End Region

    
    Private Sub SổKhoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SổKhoToolStripMenuItem.Click
        Dim frm As New frmQuanLySoKho
        frm.ShowDialog()
    End Sub

    Private Sub SystemLogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemLogToolStripMenuItem.Click
        Dim frm As New frmSystemLog
        frm.ShowDialog()
    End Sub

    Private Sub SystemLogToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemLogToolStripButton.Click
        SystemLogToolStripMenuItem_Click(Nothing, Nothing)
    End Sub
End Class
